<%= form_for @request, :url => { :controller => "admin", :action => "update_request" } do |f| %>

	<% if @request.errors.any? %>
		<div class="error_messages">
			<ul>
				<% for message in @request.errors.full_messages %>
					<li><%= message %></li>
				<% end %>
			</ul>
		</div>
	<% end %>
	
	<%= f.hidden_field :id %>

    <%= f.select :car_brand_id, options_from_collection_for_select(CarBrand.all(:order => :name), 'id', 'name', :selected => @request.car_brand_id), :include_blank => '< Марка >', :required => true %>
    
    <div id = "carModels">
		<%= render :partial => 'car_models', :locals => { :car_model_id => @request.car_model_id, :car_models => CarModel.where(:car_brand_id => @request.car_brand_id).order(:name) }  %>
	</div>
	
	<%= f.select :year, options_for_select((1960..2011).to_a.reverse, :selected => @request.year), :include_blank => '< Година >'  %><br />
	<%= f.select :engine_type_id, options_from_collection_for_select(EngineType.all, 'id', 'name', :selected => @request.engine_type_id), :include_blank => '< Mодел >'  %><br />
	<%= f.select :gearbox_type_id, options_from_collection_for_select(GearboxType.all, 'id', 'name', :selected => @request.gearbox_type_id), :include_blank => '< Скоростна кутия >'  %><br />
	<%= f.text_field :gsm, default_text((@request.gsm.nil? ? "GSM" : @request.gsm)) %><br />
	<%= f.text_field :email, default_text((@request.email.nil? ? "e-mail" : @request.email)) %><br />
	<%= f.select :city_id, options_from_collection_for_select(City.all(:order => :name), 'id', 'name', :selected => @request.city_id), :include_blank => '< Град >' %><br />
	<%= select_tag("region_ids[]", options_for_select(Region.find(:all).collect { |reg| [reg.name, reg.id] }, @request.region_requests.collect { |reg| reg.region_id }), { :multiple => true, :id => "requestRegions" } )%>	
	Authorized: <%= f.check_box :is_authorized %><br />

	<%= f.submit "Update" %>
<% end %>		

<% @request.cart.part_configurations.each do |pc| %>
	<%= render :partial => "admin/part_configuration", :locals => { :part_configuration => pc } %>
<% end %>

<script type="text/javascript">
    $(document).ready(function() {
        $("#requestRegions").multiselect();
    });
</script>